package template

import "fmt"

// 实现超类Person以及一个IPerson接口
type IPerson interface {
	SetName(name string)
	BeforeOut()
	Out()
}

type Person struct {
	Specific IPerson
	name     string
}

func (p *Person) SetName(name string) {
	p.name = name
}

func (p *Person) BeforeOut() {
	if p.Specific == nil {
		return
	}

	p.Specific.BeforeOut()
}

func (p *Person) Out() {
	p.BeforeOut()
	fmt.Println(p.name + " go out...")
}

// 实现子类Boy以及Girl
type Boy struct {
	Person
}

func (b *Boy) BeforeOut() {
	fmt.Println("get up...")
}

type Girl struct {
	Person
}

func (g *Girl) BeforeOut() {
	fmt.Println("get up and dress up...")
}
